package com.lstimeline.utility.DataManager;

import java.sql.*;
import java.util.*;

public class ViewDataManager extends AbstractDataManager {
	/**
	 * Provide a complete list of supported schools for the front page
	 */
	public static HashMap<Integer, String> getSchoolNameMap() {
		HashMap<Integer, String> schoolNames = new HashMap<Integer, String>();
		
		Connection conn = getConnection();
		if(conn != null) {
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				//Ordered alphabatically
				String queryString = "SELECT * FROM school";
				
				ps = conn.prepareStatement(queryString);
				rs = ps.executeQuery();
				
				while(rs.next()) {
					schoolNames.put(rs.getInt(1), rs.getString(2));
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					rs.close();
					ps.close();
					
					closeConnection(conn);
				} catch(Exception e) {
					e.printStackTrace();
				}
			}
			return schoolNames;
		} else {
			//conn not opened
			return null;
		}
	}
}
